//企业职位详情
import React, { Component } from 'react'
import {
    View,
    Text,
    Image,
    TouchableOpacity,
    ScrollView,
} from 'react-native';


import { Cdetailpos_Style as styles } from '../../../../styles';
import Icon from 'react-native-vector-icons/Ionicons';
import sal from '../../../util/sal';

import { UpdateStatePasueMobAction } from '../../../actions/postion_c'
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';

import {common_url, fetchRequest} from '../../../util/fetch';

var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;

class Cdetailpos_body extends Component {
    constructor(props) {
        super(props);
    }
    go(Id, welfare) {
        fetchRequest('Postion/updateStatePasueMob.go', 'POST', { postionId: Id, postionWelfare: welfare }).then(ret => {
            if (ret.statemsg == 'ok') {
                this.props.navigation.goBack();
            }
        });
    }
    render() {
        if (this.props.company != undefined) {
            return (
                <ScrollView>
                    <View style={styles.del_top}>
                        <View style={styles.del_eve1}>
                            <Text style={styles.del_pos}>{this.props.xzPostion.postionName}</Text>
                            <Text style={styles.del_money}>{sal(this.props.xzPostion.postionMm, this.props.xzPostion.postionYm)}</Text>
                        </View>

                        <View style={styles.del_eve2}>
                            <Icon
                                name={'md-pin'}
                                size={15}
                                color={'#aeaeae'} style={styles.del_areai} />
                            <Text style={styles.del_area}>{this.props.xzPostion.postionSpace}</Text>
                            <Icon
                                name={'md-calendar'}
                                size={15}
                                color={'#aeaeae'} style={styles.del_areai} />
                            <Text style={styles.del_area}>{this.props.xzPostion.postionExp}年经验</Text>
                            <Icon
                                name={'md-school'}
                                size={15}
                                color={'#aeaeae'} style={styles.del_areai} />
                            <Text style={styles.del_area}>{this.props.xzPostion.postionEducation}</Text>
                        </View>

                        <View style={styles.del_eve3}>
                            <Text style={styles.del_ben}>{this.welfareName(this.props.company.welfares)}</Text>
                        </View>
                    </View>

                    <TouchableOpacity style={styles.del_com}
                        onPress={() => { this.props.navigation.navigate('Ccombasic_all', { company: this.props.company }) }}>
                        <Image source={
                            this.props.company.companyPicture ?
                                {uri: common_url + "uploadImg/" + this.props.company.companyPicture}
                                :require('../../../img/app/company.png')} style={styles.del_head} />

                        <View style={styles.del_comright}>
                            <Text style={styles.del_comname}>
                                {this.props.company.companyName}
                            </Text>
                            <View style={styles.del_comin}>
                                <Text style={styles.del_commum}>{this.props.company.companyCity}</Text>
                                <Text style={styles.del_commum}>公司人数: {this.props.company.companyScale}</Text>
                            </View>
                        </View>
                    </TouchableOpacity>

                    <View style={styles.del_pos2}>
                        <Text style={styles.del_up}>职位描述</Text>
                        <Text style={styles.del_contain}>
                            {this.props.xzPostion.postionDescription}
                        </Text>
                    </View>

                    <View style={styles.del_pos2}>
                        <Text style={styles.del_up}>工作地点</Text>
                        <Text style={styles.del_contain}>{this.props.company.companySpace}</Text>
                    </View>

                    {this.stateshow(this.props.xzPostion.postionWelfare)}

                </ScrollView>
            )
        } else {
            return null;
        }
    }
    //待遇
    welfareName(List) {
        let arr = '';
        if (List != undefined) {
            for (let i = 0; i < List.length; i++) {
                arr += List[i].welfareName + '/';
            }
            if (arr.endsWith('/')) {
                arr = arr.substr(0, arr.length - 1);
            }
        }
        return arr;
    }

    stateshow(postionWelfare) {
        if (postionWelfare == 1) {
            <View style={styles.del_but1}>
                <TouchableOpacity style={[styles.del_rec2, { width: width * 0.85 }]} activeOpacity={1} underlayColor="#aeaeae">
                    <Text style={styles.del_butin}>审核中</Text>
                </TouchableOpacity>
            </View>
        } else if (postionWelfare == 2) {
            <View style={styles.del_but1}>
                <TouchableOpacity style={[styles.del_rec2, { width: width * 0.85 }]} activeOpacity={1} underlayColor="#aeaeae">
                    <Text style={styles.del_butin}>审核未通过</Text>
                </TouchableOpacity>
            </View>
        } else if (postionWelfare == 3) {
            return (
                <View style={styles.del_but2}>
                    <TouchableOpacity
                        style={[styles.del_edit, { width: width * 0.4 }]}
                        activeOpacity={1}
                        onPress={() => {
                            this.go(this.props.xzPostion.postionId, 5);
                            // this.props.actions.UpdateStatePasueMobAction({ postionId: this.props.xzPostion.postionId, postionWelfare: 5 })
                        }}>
                        <Text style={styles.del_butin}>结束职位</Text>
                    </TouchableOpacity>
                    <TouchableOpacity
                        style={[styles.del_edit, { width: width * 0.4 }]}
                        activeOpacity={1}
                        onPress={() => {
                            this.go(this.props.xzPostion.postionId, 4);
                        }}>
                        <Text style={styles.del_butin}>暂停职位</Text>
                    </TouchableOpacity>
                </View>
            )
        } else if (postionWelfare == 4) {
            return (
                <View style={styles.del_but2}>
                    <TouchableOpacity
                        style={[styles.del_edit, { width: width * 0.4 }]}
                        activeOpacity={1}
                        onPress={() => {
                            this.go(this.props.xzPostion.postionId, 5);
                        }}>
                        <Text style={styles.del_butin}>结束职位</Text>
                    </TouchableOpacity>
                    <TouchableOpacity
                        style={[styles.del_edit, { width: width * 0.4 }]}
                        activeOpacity={1}
                        onPress={() => {
                            this.go(this.props.xzPostion.postionId, 3);
                        }}>
                        <Text style={styles.del_butin}>恢复职位</Text>
                    </TouchableOpacity>
                </View>
            )
        } else if (postionWelfare == 5) {
            return (
                <View style={styles.del_but1}>
                    <TouchableOpacity style={[styles.del_rec2, { width: width * 0.85 }]} activeOpacity={1} underlayColor="#aeaeae">
                        <Text style={styles.del_butin}>已结束</Text>
                    </TouchableOpacity>
                </View>
            )
        }
    }
}

//组合action
var actions = {
    UpdateStatePasueMobAction,
}
//连接state到props
const mapStateToProps = state => {
    return {
        msg: state.UpdateStatePasueMobReducer             //自己的reducers
    }
}
//连接action
const mapDispatchToProps = (dispatch) => {
    return {
        actions: bindActionCreators(actions, dispatch)
    }
}
//导出组合好的组件(组合后状态改变重新渲染组合组件的页面)
export default connect(
    mapStateToProps, mapDispatchToProps
)(Cdetailpos_body);